<template>
  <div class="container">
    <div class="exchange-wrapper" v-if="type !== 'msg'">
      <div class="forum-item" v-for="item in lists" @click="toDetail(item)">
        <div class="forum-item-top">
          <p>{{item.title}}</p>
        </div>
        <div class="forum-item-bottom">
          <span class="user-text">{{item.addman}}</span>
          <span class="create-time">{{item.addtime}}</span>
        </div>
      </div>
    </div>

    <div class="exchange-wrapper" v-else>
      <div class="forum-item" v-for="item in lists" @click="toDetail(item)">
        <div class="forum-item-top">
          <p>{{item.title}}</p>
        </div>
        <div class="forum-item-bottom">
          <span class="user-text">{{item.manto}}</span>
          <span class="create-time">{{item.sendtime}}</span>
        </div>
      </div>
    </div>
    <div v-if="lists.length == 0" class="nodata">--- 暂无数据 ---</div>
  </div>
</template>

<script>
  import util from '@/common/util';
  export default {
    name: "study-notice",
    data() {
      return {
        id: '',
        type: '',
        page: 1,
        lists:[],
      }
    },
    created() {
      if(util.storage.get('userinfo')){
        this.id = util.storage.get('userinfo').id;
      }
      this.type = this.$route.query.type;
      console.log('type',this.type);
      if(this.type == 'notice'){
        this.getNoticeList()
      } else if(this.type == 'task') {
        this.getTaskList();
      } else if(this.type == 'msg') {
        this.getMsgList();
      }
    },
    methods: {

      getNoticeList() {  // 获取公告列表
        let that = this;
        that.$api.post('/mobile/Gonggao/index', {'user':{'page':that.page}}, r => {
          console.log(r)
          that.lists = r.data;
        })
      },

      getTaskList() {  // 获取作业列表
        let that = this;
        that.$api.post('/mobile/Gonggao/zuoye', {'user':{'page':that.page}}, r => {
          that.lists = r.data;
        })
      },

      getMsgList() {  // 获取消息列表
        let that = this;
        that.$api.post('/mobile/Stmsg/index', {'user':{'id':that.id,'page':that.page}}, r => {
          that.lists = r.data;
        })
      },

      toDetail(item) {
        let that = this;
        that.$router.push({path:'/studyNoticeDetail',query:{id:item.id,type: that.type}})
      }
    }
  }
</script>

<style scoped>

</style>
